package model.mediators;

import java.util.List;

import model.entity.Entity;
import model.item.Inventory;
import model.item.InventoryItem;
import model.map.GameMap;
import model.map.MapPoint;

/**
 * If an inventory needs to drop an item, it uses this mediator to interact with the map.
 * @author Drew
 *
 */
public class DropItemMediator extends MapMediator {
	
/**
 * This method checks to see whether the drop location is a valid location on the map. If it is, then the item
 * gets added to the map. If not, then nothing changes.
 * @param inventory
 * @param item
 * @param location
 */
	public static void drop(Inventory inventory, InventoryItem item, MapPoint location) {
		GameMap gameMap = MapMediator.getMap();
		if (gameMap.validLocation(location)) {
			List<Entity> entityList = gameMap.getEntitiesOnTile(location);
			if (entityList.isEmpty() && gameMap.getObstaclesOnTile(location).isEmpty()) {
				inventory.removeItem(item);	
				gameMap.addItemToTile(item, location);	
			}
			
			else {
				return;
			}
			}
		else {
			return;
		}
	}
}
